package com.garagesale.data;
// Generated May 3, 2011 8:59:20 PM by Hibernate Tools 3.2.1.GA

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * User generated by hbm2java
 */
@Entity
@Table(name = "user", catalog = "garage_sale")
public class User implements java.io.Serializable
{

    private Integer userId;
    private String lastName;
    private String firstName;
    private String username;
    private String password;
    private String emailAddress;
    private String userRole;
    private Set<Item> itemsForBuyerUserID = new HashSet<Item>(0);
    private Set<Item> itemsForSellerUserID = new HashSet<Item>(0);
    private Set<ShoppingCart> shoppingCarts = new HashSet<ShoppingCart>(0);

    public User()
    {
    }

    public User(String lastName, String firstName, String username, String password)
    {
        this.lastName = lastName;
        this.firstName = firstName;
        this.username = username;
        this.password = password;
    }

    public User(String lastName, String firstName, String username, String password, String emailAddress, Set<Item> itemsForBuyerUserId, Set<Item> itemsForSellerUserId, Set<ShoppingCart> shoppingCarts)
    {
        this.lastName = lastName;
        this.firstName = firstName;
        this.username = username;
        this.password = password;
        this.emailAddress = emailAddress;
        this.itemsForBuyerUserID = itemsForBuyerUserId;
        this.itemsForSellerUserID = itemsForSellerUserId;
        this.shoppingCarts = shoppingCarts;
    }

    public User(String lastName, String firstName, String username, String password, String emailAddress, String userRole)
    {
        this.lastName = lastName;
        this.firstName = firstName;
        this.username = username;
        this.password = password;
        this.emailAddress = emailAddress;
        this.userRole = userRole;
    }


    

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "user_id", unique = true, nullable = false)
    public Integer getUserID()
    {
        return this.userId;
    }

    public void setUserID(Integer userId)
    {
        this.userId = userId;
    }

    @Column(name = "last_name", nullable = false, length = 45)
    public String getLastName()
    {
        return this.lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    @Column(name = "first_name", nullable = false, length = 45)
    public String getFirstName()
    {
        return this.firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    @Column(name = "username", nullable = false, length = 45)
    public String getUsername()
    {
        return this.username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }

    @Column(name = "password", nullable = false, length = 128)
    public String getPassword()
    {
        return this.password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    @Column(name = "email_address", length = 45)
    public String getEmailAddress()
    {
        return this.emailAddress;
    }

    public void setEmailAddress(String emailAddress)
    {
        this.emailAddress = emailAddress;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userByBuyerUserId")
    public Set<Item> getItemsForBuyerUserID()
    {
        return this.itemsForBuyerUserID;
    }

    public void setItemsForBuyerUserID(Set<Item> itemsForBuyerUserId)
    {
        this.itemsForBuyerUserID = itemsForBuyerUserId;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userBySellerUserId")
    public Set<Item> getItemsForSellerUserID()
    {
        return this.itemsForSellerUserID;
    }

    public void setItemsForSellerUserID(Set<Item> itemsForSellerUserId)
    {
        this.itemsForSellerUserID = itemsForSellerUserId;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
    public Set<ShoppingCart> getShoppingCarts()
    {
        return this.shoppingCarts;
    }

    public void setShoppingCarts(Set<ShoppingCart> shoppingCarts)
    {
        this.shoppingCarts = shoppingCarts;
    }

    @Column(name = "user_role", length = 45)
    public String getUserRole()
    {
        return userRole;
    }

    public void setUserRole(String userRole)
    {
        this.userRole = userRole;
    }

    public ShoppingCart getShoppingCart()
    {
        if (null != shoppingCarts && shoppingCarts.size() > 0)
        {
            return shoppingCarts.iterator().next();
        }
        return null;
    }

}
